//package com.tcoiss.datafactory.util;
//
//import java.sql.*;
//
//import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy;
//
//public class BulkCopySingle {
////    public static void main(String[] args) {
////        String connectionUrl = "jdbc:sqlserver://<server>:<port>;databaseName=AdventureWorks;user=<user>;password=<password>";
////        String destinationTable = "dbo.BulkCopyDemoMatchingColumns";
////        int countBefore, countAfter;
////        ResultSet rsSourceData;
////
////        try (Connection sourceConnection = DriverManager.getConnection(connectionUrl);
////             Connection destinationConnection = DriverManager.getConnection(connectionUrl);
////             Statement stmt = sourceConnection.createStatement();
////             SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(destinationConnection)) {
////
////            // Empty the destination table.
////            stmt.executeUpdate("DELETE FROM " + destinationTable);
////
////            // Perform an initial count on the destination table.
////            countBefore = getRowCount(stmt, destinationTable);
////
////            // Get data from the source table as a ResultSet.
////            rsSourceData = stmt.executeQuery("SELECT ProductID, Name, ProductNumber FROM Production.Product");
////
////            // In real world applications you would
////            // not use SQLServerBulkCopy to move data from one table to the other
////            // in the same database. This is for demonstration purposes only.
////
////            // Set up the bulk copy object.
////            // Note that the column positions in the source
////            // table match the column positions in
////            // the destination table so there is no need to
////            // map columns.
////            bulkCopy.setDestinationTableName(destinationTable);
////
////            // Write from the source to the destination.
////            bulkCopy.writeToServer(rsSourceData);
////
////            // Perform a final count on the destination
////            // table to see how many rows were added.
////            countAfter = getRowCount(stmt, destinationTable);
////            System.out.println((countAfter - countBefore) + " rows were added.");
////        }
////        // Handle any errors that may have occurred.
////        catch (SQLException e) {
////            e.printStackTrace();
////        }
////    }
////
////    private static int getRowCount(Statement stmt,
////                                   String tableName) throws SQLException {
////        ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName);
////        rs.next();
////        int count = rs.getInt(1);
////        rs.close();
////        return count;
////    }
//
////    public static void main(String[] args) throws Exception
////    {
////
////        String goodsName = "56寸及以上 彩电底座安装调试服务包";
////        int length = goodsName.length();
////        if(goodsName.length()>40) {
////            System.out.println(goodsName.substring(0, 40));//商品名称(必填)
////
////        }
////        System.out.println(length);//商品名称(必填)
////        String tableName = "batchTest";
////        String tableNameBulkCopyAPI = "batchTestBulk";
////
////        String connectionUrl = "jdbc:sqlserver://<server>:<port>;databaseName=<database>;user=<user>;password=<password>";
////
////        try (Connection con = DriverManager.getConnection(connectionUrl);
////             Statement stmt = con.createStatement();
////             PreparedStatement pstmt = con.prepareStatement("insert into " + tableName + " values (?, ?)");) {
////
////            String dropSql = "if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + tableName + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) DROP TABLE [" + tableName + "]";
////            stmt.execute(dropSql);
////
////            String createSql = "create table " + tableName + " (c1 int, c2 varchar(20))";
////            stmt.execute(createSql);
////
////            System.out.println("Starting batch operation using regular batch insert operation.");
////            long start = System.currentTimeMillis();
////            for (int i = 0; i < 1000; i++) {
////                pstmt.setInt(1, i);
////                pstmt.setString(2, "test" + i);
////                pstmt.addBatch();
////            }
////            pstmt.executeBatch();
////
////            long end = System.currentTimeMillis();
////
////            System.out.println("Finished. Time taken : " + (end - start) + " milliseconds.");
////        }
////
////        try (Connection con = DriverManager.getConnection(connectionUrl + ";useBulkCopyForBatchInsert=true");
////             Statement stmt = con.createStatement();
////             PreparedStatement pstmt = con.prepareStatement("insert into " + tableNameBulkCopyAPI + " values (?, ?)");) {
////
////            String dropSql = "if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + tableNameBulkCopyAPI + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) DROP TABLE [" + tableNameBulkCopyAPI + "]";
////            stmt.execute(dropSql);
////
////            String createSql = "create table " + tableNameBulkCopyAPI + " (c1 int, c2 varchar(20))";
////            stmt.execute(createSql);
////
////            System.out.println("Starting batch operation using Bulk Copy API.");
////            long start = System.currentTimeMillis();
////            for (int i = 0; i < 1000; i++) {
////                pstmt.setInt(1, i);
////                pstmt.setString(2, "test" + i);
////                pstmt.addBatch();
////            }
////            pstmt.executeBatch();
////
////            long end = System.currentTimeMillis();
////
////            System.out.println("Finished. Time taken : " + (end - start) + " milliseconds.");
////        }
//    }
//}
